class SnapshotArray
{
public:
    SnapshotArray(int length) : data(length)
    {
    }

    void set(int index, int val)
    {
        data[index][isnap] = val;
    }

    int snap()
    {
        ++isnap;
        return isnap - 1;
    }

    int get(int index, int snap_id)
    {
        auto it = data[index].upper_bound(snap_id);
        if (it == data[index].begin())
        {
            return 0;
        }
        return (--it)->second;
    }

private:
    int isnap = 0;
    vector<map<int, int>> data;
};

/**
 * Your SnapshotArray object will be instantiated and called as such:
 * SnapshotArray* obj = new SnapshotArray(length);
 * obj->set(index,val);
 * int param_2 = obj->snap();
 * int param_3 = obj->get(index,snap_id);
 */